<?php
namespace Models\Model;

use Zend\Db\ResultSet\ResultSet;
use Zend\Db\TableGateway\TableGateway;
use Zend\Db\Sql;
use Zend\Db\Sql\Where;
use Zend\Db\Sql\Select;
use Zend\Paginator\Adapter\DbSelect;
use Zend\Paginator\Paginator;
use Zend\Db\Sql\Predicate;
use Zend\Db\Sql\Expression;

class SubscribeTable
{
    protected $tableGateway;
	protected $select;
    public function __construct(TableGateway $tableGateway)
    {
        $this->tableGateway = $tableGateway;
		$this->select = new Select();
    }
	public function addSubscribe($s_email)
    {
		$data = array(
			'subscrib_email' => $s_email, 			
			's_status'  	 => 1,  	
			'date_added' 	 => date('Y-m-d H:i:s'),   
			'date_updated'	 => date('Y-m-d H:i:s'), 				
		);	
		$insertresult=$this->tableGateway->insert($data);	
		return $insertresult;	
    }	
	public function checkEmail($s_email)
    {	
		$select = $this->tableGateway->getSql()->select();			
		$select->where('subscrib_email="'.$s_email.'"');
		$resultSet = $this->tableGateway->selectWith($select);
		$is_exists = $resultSet->count();
		return $is_exists;		
	}
	public function allsubscribers(){
		$select = $this->tableGateway->getSql()->select();			
		$select->where('s_status=1');
		$alllist = $this->tableGateway->selectWith($select);	
		return $alllist;
	}
	public function unsubscribe($status,$s_email)
    {	
		$data = array(
			's_status' 	  	=> $status, 
			'date_updated'	=> date('Y-m-d H:i:s'),
		);
		$updaed_status=$this->tableGateway->update($data, array('subscrib_email' => $s_email));
		return 	$updaed_status;			
	}
}